package org.eclipsecon.dui.example;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.widgets.Display;
import org.eclipsecon.dui.interpreter.IContextAware;
import org.eclipsecon.dui.interpreter.IModelContext;

public class RevertAction implements SelectionListener, IContextAware {

	private IModelContext context;

	@Override
	public void widgetDefaultSelected(SelectionEvent e) {
	}

	@Override
	public void widgetSelected(SelectionEvent e) {
		if ( context.getModel() == null) {
			MessageDialog.openError(Display
					.getDefault().getActiveShell(), "Nothing to revert",
					"Load a model prior to revert");
			return;
		}
		boolean openConfirm = MessageDialog.openConfirm(Display.getDefault()
				.getActiveShell(), "Revert Model",
				"Do you really want to revert your model?");
		if (openConfirm) {
			context.revertModel();
		}

	}

	@Override
	public void setContext(IModelContext context) {
		this.context = context;

	}
}